import secrets

from otree.api import *

from gambler_fallacy_kline import rising5, falling5, rising7, rising10, falling7, falling10

# import falling5
# import rising5

doc = """
赌徒谬误独立决策组
"""


class C(BaseConstants):
    NAME_IN_URL = 'gfk'
    PLAYERS_PER_GROUP = None
    NUM_ROUNDS = 10
    TABLE_STYLE = """
<style>
        img {
            width: auto;
            height: 300px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0; /* 适当减小表格的上下外边距，更适合手机布局 */
            font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif; /* 选择适合中文显示的字体 */
            min-width: 280px; /* 减小最小宽度，适应手机屏幕 */
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* 调小阴影范围 */
        }

        th {
            background-color: #f2f2f2;
            color: #333;
            text-align: left;
            padding: 10px 12px; /* 适当减小内边距，节省空间 */
            font-size: 16px; /* 设置适合手机阅读的字体大小 */
        }

        caption {
            padding: 8px; /* 减小标题内边距 */
            caption-side: bottom;
            color: #777;
            font-size: 14px; /* 调整标题字体大小 */
            margin-top: 8px;
        }

        td {
            padding: 10px 12px; /* 适当减小内边距，节省空间 */
            text-align: left;
            font-size: 14px; /* 设置适合手机阅读的字体大小 */
        }

        tr:nth-child(even) td {
            background-color: #f2f2f2;
        }

        tr:nth-child(odd) td {
            background-color: #fff;
        }

        tr:hover td {
            background-color: #e9f3ff;
        }

        th,
        td {
            border: 1px solid #e0e0e0;
        }
    </style>
"""


TREND_UP, TREND_DOWN = '上涨', '下跌'
YES, NO = "是", "否"
LABEL_PIC_CURRENT_TREND = '当前股票价格走势'
LABEL_PIC_NEXT_TREND = '下个交易日股票涨跌情况'
LABEL_PIC_NEXT_TREND2 = '下个交易日股票涨跌情况'


class Subsession(BaseSubsession):
    pass


class Group(BaseGroup):
    pass


class Player(BasePlayer):
    gf_up_curr = models.StringField(choices=[TREND_UP, TREND_DOWN], label=LABEL_PIC_CURRENT_TREND,
                                    widget=widgets.RadioSelectHorizontal)

    gf_up_next = models.StringField(choices=[TREND_UP, TREND_DOWN], label=LABEL_PIC_NEXT_TREND,
                                    widget=widgets.RadioSelectHorizontal)

    gf_dw_curr = models.StringField(choices=[TREND_UP, TREND_DOWN], label=LABEL_PIC_CURRENT_TREND,
                                    widget=widgets.RadioSelectHorizontal)

    gf_dw_next = models.StringField(choices=[TREND_UP, TREND_DOWN], label=LABEL_PIC_NEXT_TREND,
                                    widget=widgets.RadioSelectHorizontal)


rising_data = rising5.DATA
rising_data.extend(rising7.DATA)
rising_data.extend(rising10.DATA)

falling_data = falling5.DATA
falling_data.extend(falling7.DATA)
falling_data.extend(falling10.DATA)


def get_random_data(data_list):
    return secrets.choice(data_list)


class KLineChartUp(Page):
    form_model = 'player'
    form_fields = ['gf_up_curr', 'gf_up_next']

    def vars_for_template(self):
        # 使用rising5.DATA数据进行解析，并随机选择一组
        selected_data = get_random_data(rising_data)

        return {
            'stock_data': selected_data,
            'num_days': len(selected_data)
        }


class KLineChartDown(Page):
    form_model = 'player'
    form_fields = ['gf_dw_curr', 'gf_dw_next']

    def vars_for_template(self):
        # 使用falling5.DATA数据进行解析，并随机选择一组
        selected_data = get_random_data(falling_data)

        return {
            'stock_data': selected_data,
            'num_days': len(selected_data)
        }


page_sequence = [
    # Start,
    KLineChartUp,
    KLineChartDown
]
